package com.usian.controller;

import com.alibaba.fastjson.JSON;
import com.usian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class HelloController {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;
    @RequestMapping("hello")
    public String hello(){
        User user = new User();
        user.setAge(18);
        user.setName("张三");
        List<String> list = new ArrayList<>();
        list.add("上海");
        list.add("北京");
        list.add("深圳");
        user.setData(list);

        kafkaTemplate.send("kafka-hello", JSON.toJSONString(user));
        return "ok";
    }
}
